<template>
  <div>

    <div>
      <el-table :data="tableData" border>
        <el-table-column prop="ordercode" label="订单号"/>
        <el-table-column prop="account.username" label="负责人"/>
        <el-table-column prop="object.name" label="供应商"/>
        <el-table-column prop="status" label="状态">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.status==0" effect="dark" type="success">已处理</el-tag>
            <el-tag v-if="scope.row.status==1" effect="dark" type="info">未处理</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="details" label="订单详情">
          <template slot-scope="scope">
            <el-popover
              placement="right"
              width="400"
              trigger="click"
            >
              <el-table :data="scope.row.details">
                <el-table-column property="product.name" label="产品名"/>
                <el-table-column property="product.brand" label="品牌"/>
                <el-table-column property="product.model.info" label="产品类型"/>
                <el-table-column property="quantity" label="数量"/>
                <el-table-column property="supplyPrice" label="采购价格"/>
                <el-table-column property="suggestedPrice" label="建议价格"/>
              </el-table>
              <el-button slot="reference">详情</el-button>
            </el-popover>

          </template>
        </el-table-column>
        <el-table-column prop="price" label="总额(元)"/>
        <el-table-column prop="createTime" label="更新时间"/>
        <el-table-column
          fixed="right"
          label="操作"
          width="100"
        >
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="handleClick(scope.row)">查看</el-button>
            <el-button type="text" size="small">编辑</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="block">
      <el-pagination
        :page-size="limit"
        :total="total"
        style="padding:30px 0;text-align:center;"
        layout="total,prev,pager,next,jumper"
        @current-change="getPagedata"
      />
    </div>
    <el-dialog
      title="提示"
      :visible.sync="dialogVisible"
      width="50%"
      :before-close="handleClose"
    >

      <el-descriptions class="margin-top" title="仓库管理员" :column="4" border >
        <template slot="extra">
         {{name}}
        </template>
        <el-descriptions-item >
          <template slot="label">
            <i class="el-icon-user"></i>
            采购人
          </template>
          {{productinfo.account.username}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-date"></i>
            采购时间
          </template>
          {{productinfo.createTime}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-tickets"></i>
            供应商
          </template>
          {{productinfo.object.name}}
        </el-descriptions-item>
      </el-descriptions>
      <el-select v-model="value"  placeholder="请选择"  style="margin-top: 20px">
        <el-option
          v-for="item in options"
          :key="item.value"
          :label="item.label"
          :value="item.value">
        </el-option>
      </el-select>
      <el-table
        :data="productinfo.details"
        stripe
        border
        style="width: 100%;margin-top: 20px">
        <el-table-column
          prop="product.name"
          label="名称"
         >
        </el-table-column>
        <el-table-column
          prop="product.brand"
          label="品牌"
          >
        </el-table-column>
        <el-table-column
          prop="quantity"
          label="待入库数">
        </el-table-column>
        <el-table-column
          prop="supplyPrice"
          label="采购价钱(元)"
         >
        </el-table-column>
        <el-table-column
          prop="supplyPrice"
          label="入库数"
        >
          <template slot-scope="scope">
            <el-input></el-input>
          </template>
        </el-table-column>
        <el-table-column
          prop="supplyPrice"
          label="不合格数"
        >
          <template slot-scope="scope">
            <el-input></el-input>
          </template>
        </el-table-column>
        <el-table-column
          prop="supplyPrice"
          label="本次入库数"
        >
          <template slot-scope="scope">
            <el-input></el-input>
          </template>
        </el-table-column>
        <el-table-column
          label="入库金额"
        >
        </el-table-column>
      </el-table>

      <el-divider><i class="el-icon-s-data"></i></el-divider>
      <div style="margin-top: 20px">
        入库总数<el-input ></el-input>
        入库总金额<el-input ></el-input>
      </div>
      <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消 入 库</el-button>
    <el-button type="primary" @click="dialogVisible = false">确 定 入 库</el-button>
  </span>
    </el-dialog>
  </div>
</template>

<script>
import orderApi from '@/api/order/order'
import supplierApi from '@/api/supplier/supplier'
import { mapGetters } from 'vuex'

export default {
  computed: {
    ...mapGetters([
      'name',
      'id'
    ])
  },
  data() {
    return {
      formData: {},

      options: [
        {
          value: '-1',
          label: '全部'
        },
        {
          value: '0',
          label: '已处理'
        },
        {
          value: '1',
          label: '未处理'
        }],
      tableData: null,
      current: 1, // 当前页
      limit: 10, // 每页显示记录数
      total: 0, // 总记录数
      dialogVisible: false,

      allsupplier: null,
      productinfo: {
        account: {},
        object: {}
      }

    }
  },
  created() {
    this.getdata()
    this.getsupplier()
  },
  methods: {

    getsupplier() {
      supplierApi.getAllsupplier().then(res => {
        this.allsupplier = res.data
      })
    },

    // 获取数据
    getdata() {
      this.formData.status = 1
      this.formData.page = this.current
      this.formData.limit = this.limit
      orderApi.showpurchase(this.formData).then(
        res => {
          this.tableData = res.data.list
          this.total = res.data.total
        }
      )
    },
    getPagedata(page = 1) {
      this.formData.status = 1
      this.current = page
      this.formData.page = this.current
      this.formData.limit = this.limit
      orderApi.showpurchase(this.formData).then(
        res => {
          this.tableData = res.data.list
          this.total = res.data.total
        }
      )
    },

    handleClick(data) {
      this.dialogVisible = true
      this.productinfo = data
      console.log(this.productinfo)
    },
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          this.$message('取消操作')
          done()
        })
        .catch(_ => {
        })
    }
  }
}
</script>

<style scoped lang="scss">

</style>

